package com.campus.dao.provider;

import java.util.Map;
import com.campus.pojo.Notice;
import com.campus.pojo.SysUser;

import javax.servlet.http.HttpServletRequest;

public class NoticeDynaSqlProvider {
    // 分页动态查询通知
    public String selectWithParam(Map<String, Object> params) {

        String sql = "select * from notice where 1=1 ";
        if (params.get("notice") != null) {
            Notice notice = (Notice) params.get("notice");
            if (notice.getTitle() != null && !notice.getTitle().isEmpty()) {
                sql += " and title LIKE '%" + notice.getTitle() + "%' ";
            }
            sql += " and userId ='" + notice.getUserId() + "'";
            sql += " order by operateTime desc";
        }
        if (params.get("repair") != null){
            sql += " and type = 3";
        }else {
            sql += " and type <> 3";
        }
        sql += " and userId ='"+ params.get("userId") +"'";//属于登录用户的消息
        //order by
        sql +=" order by operateTime desc";

        if (params.get("pager") != null) {
            sql += " limit #{pager.firstLimitParam} , #{pager.perPageRows}  ";
        }
        //System.out.println(sql);//调试
        return sql;
    }

    // 动态查询通知总记录数
    public String count(Map<String, Object> params) {
        //当前登录用户的id
        String sql = "select count(*) from notice where 1=1 ";
        if (params.get("notice") != null) {
            Notice notice = (Notice) params.get("notice");
            if (notice.getTitle() != null && !notice.getTitle().isEmpty()) {
                sql += " and title LIKE '%" + notice.getTitle() + "%' ";
            }
            sql += " and userId ='" + notice.getUserId() + "'";
            sql += " order by operateTime desc";
        }
        if (params.get("repair") != null){
            sql += " and type = 3";
        }else {
            sql += " and type <> 3";
        }
        sql += " and userId ='"+ params.get("userId") +"'";//属于登录用户的消息
        return sql;
    }

}
